﻿package mortal.game.view.chat
{
    import Message.Public.*;
    import __AS3__.vec.*;
    import com.gengine.utils.pools.*;
    import com.mui.controls.*;
    import extend.language.*;
    import fl.controls.*;
    import flash.display.*;
    import flash.filters.*;
    import flash.utils.*;
    import mortal.game.events.*;
    import mortal.game.manager.msgTip.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.*;
    import mortal.game.view.chat.chatPanel.*;
    import mortal.game.view.chat.chatPrivate.*;
    import mortal.game.view.chat.chatViewData.*;
    import mortal.game.view.common.drag.*;
    import mortal.mvc.core.*;

    public class ChatBody extends Sprite
    {
        private var _scrollPane:GScrollPane;
        private var _dataArray:Array;
        private var _currentChatBox:Sprite;
        private var _dicNameChatBox:Dictionary;
        public var msgBox:ChatMsgBox;
        private var _dragItem:DragItem;
        private const MaxHeight:Number = 192;
        private const MinHeight:Number = 60;
        private var _currentHeight:Number = 192;
        private var _lastDragHeight:Number;
        public static var lineHeight:Number = 21;
        public static var lineWidth:Number = 300;

        public function ChatBody(param1:Array)
        {
            this._dataArray = param1;
            this.mouseEnabled = false;
            this.init();
            return;
        }// end function

        private function init() : void
        {
            this.initBody();
            this.initScrollPane();
            this.addMessage();
            return;
        }// end function

        private function initBody() : void
        {
            var _loc_2:Object = null;
            var _loc_3:ChatBox = null;
            this._dataArray = ChatMessageWorking.chatShowAllAreaData;
            this._dicNameChatBox = new Dictionary();
            var _loc_1:int = 0;
            while (_loc_1 < this._dataArray.length)
            {
                
                _loc_2 = this._dataArray[_loc_1];
                _loc_3 = new ChatBox(30);
                _loc_3.name = _loc_2["name"];
                _loc_3.y = 0;
                this._dicNameChatBox[_loc_2["name"]] = _loc_3;
                if (_loc_1 == 0)
                {
                    this._currentChatBox = _loc_3;
                }
                _loc_1++;
            }
            return;
        }// end function

        private function initScrollPane() : void
        {
            this._scrollPane = new GScrollPane();
            this._scrollPane.verticalScrollBarPos = GScrollPane.SCROLLBARPOSITIONLEFT;
            this._scrollPane.width = 313;
            this._scrollPane.y = 0;
            this._scrollPane.height = this._currentHeight;
            this._scrollPane.styleName = "chatScrollPane";
            this._scrollPane.horizontalScrollPolicy = ScrollPolicy.OFF;
            this._scrollPane.verticalScrollPolicy = ScrollPolicy.ON;
            this._scrollPane.source = this._currentChatBox;
            this._scrollPane.mouseEnabled = false;
            (this._scrollPane.content as DisplayObjectContainer).mouseEnabled = false;
            this.addChild(this._scrollPane);
            this._currentChatBox.parent.mouseEnabled = false;
            this._scrollPane.refreshPane();
            this._scrollPane.update();
            return;
        }// end function

        public function addMessage(param1:String = "") : void
        {
            var _loc_2:* = Language.getString(21369);
            var _loc_3:* = ObjectPool.getObject(ChatItemData);
            var _loc_4:* = new ChatItem();
            _loc_4.setFilter([new DropShadowFilter(0, 120, 2761247, 0.8, 2, 2, 0.5)]);
            _loc_3.cellVector = ChatMessageWorking.getCellDataAnalyzeBR(_loc_2, 16735067, 12);
            var _loc_5:* = new ChatNotes();
            _loc_5.init(_loc_3, lineWidth, lineHeight);
            (this._dicNameChatBox[ChatArea.Complex] as ChatBox).addChatNotes(_loc_5);
            return;
        }// end function

        public function onStartDrag(event:DragItemEvent) : void
        {
            this._lastDragHeight = this._currentHeight;
            return;
        }// end function

        public function onDragPositionChange(event:DragItemEvent) : void
        {
            this._currentHeight = this._lastDragHeight - event.changeY;
            this._currentHeight = this._currentHeight > this.MaxHeight ? (this.MaxHeight) : (this._currentHeight);
            this._currentHeight = this._currentHeight < this.MinHeight ? (this.MinHeight) : (this._currentHeight);
            this.setSize(ChatModule.ChatWidth, this._currentHeight);
            this.y = -1 * (this._currentHeight + 43);
            Dispatcher.dispatchEvent(new DataEvent(EventName.ChatResize));
            return;
        }// end function

        public function addChatNotes(param1:ChatData, param2:Array = null) : void
        {
            var _loc_12:ChatItemData = null;
            var _loc_13:Vector.<ChatCellData> = null;
            var _loc_14:ChatNotes = null;
            var _loc_15:String = null;
            var _loc_16:Boolean = false;
            param1.content = "：" + param1.content;
            if (param2.indexOf(ChatArea.Force) == -1)
            {
                param2.push(ChatArea.Force);
            }
            var _loc_3:* = param1.typeArea;
            var _loc_4:* = param1.force;
            var _loc_5:* = param1.faceAuthority;
            var _loc_6:* = param1.fromMiniPlayer;
            var _loc_7:* = param1.chatColor;
            var _loc_8:* = this._scrollPane.verticalScrollPosition == this._scrollPane.maxVerticalScrollPosition;
            var _loc_9:* = this._scrollPane.verticalScrollPosition;
            var _loc_10:Boolean = false;
            var _loc_11:Number = 0;
            _loc_10 = this._currentChatBox is ChatBox && (this._currentChatBox as ChatBox).isMaxLength();
            if (_loc_10)
            {
                _loc_11 = (this._currentChatBox as ChatBox).getChatNotesAtIndex(0).height;
                _loc_9 = _loc_9 - _loc_11;
            }
            if (param2.indexOf(_loc_3) < 0 && _loc_3 != ChatArea.Speaker)
            {
                return;
            }
            for each (_loc_15 in param2)
            {
                
                if (_loc_3 == _loc_15 || _loc_3 == ChatArea.Speaker && _loc_15 == ChatArea.World)
                {
                    _loc_12 = ObjectPool.getObject(ChatItemData);
                    _loc_12.type = ChatMessageWorking.getChatTypeByAreaName(_loc_3);
                    _loc_13 = new Vector.<ChatCellData>;
                    _loc_16 = ChatMessageWorking.chatChannelsData.indexOf(ChatMessageWorking.forceObj) > -1 && _loc_3 == ChatArea.Force;
                    if (_loc_16 && _loc_4 != -1)
                    {
                        _loc_13 = _loc_13.concat(ChatMessageWorking.getForcePlayerCellData(_loc_6, _loc_4));
                    }
                    else if (_loc_3 == ChatArea.Union)
                    {
                        _loc_13 = _loc_13.concat(ChatMessageWorking.getCellDataByPlayerInfo(param1, true));
                    }
                    else
                    {
                        _loc_13 = _loc_13.concat(ChatMessageWorking.getCellDataByPlayerInfo(param1));
                    }
                    if (param1.alyzType == 1)
                    {
                        _loc_13 = _loc_13.concat(ChatMessageWorking.getCellDatasByAnalyzeRumor(param1.content, []));
                    }
                    else
                    {
                        _loc_13 = _loc_13.concat(ChatMessageWorking.getCellDatas(param1));
                    }
                    _loc_12.cellVector = _loc_13;
                    _loc_14 = ObjectPool.getObject(ChatNotes);
                    _loc_14.init(_loc_12, lineWidth, lineHeight);
                    (this._dicNameChatBox[_loc_15] as ChatBox).addChatNotes(_loc_14);
                    if (!_loc_16)
                    {
                        _loc_12 = ObjectPool.getObject(ChatItemData);
                        _loc_12.type = ChatMessageWorking.getChatTypeByAreaName(_loc_3);
                        _loc_13 = new Vector.<ChatCellData>;
                        if (_loc_3 == ChatArea.Union)
                        {
                            _loc_13 = _loc_13.concat(ChatMessageWorking.getCellDataByPlayerInfo(param1, true));
                        }
                        else
                        {
                            _loc_13 = _loc_13.concat(ChatMessageWorking.getCellDataByPlayerInfo(param1));
                        }
                        if (param1.alyzType == 1)
                        {
                            _loc_13 = _loc_13.concat(ChatMessageWorking.getCellDatasByAnalyzeRumor(param1.content, []));
                        }
                        else
                        {
                            _loc_13 = _loc_13.concat(ChatMessageWorking.getCellDatas(param1));
                        }
                        _loc_12.cellVector = _loc_13;
                        _loc_14 = ObjectPool.getObject(ChatNotes);
                        _loc_14.init(_loc_12, lineWidth, lineHeight);
                        (this._dicNameChatBox[ChatArea.Complex] as ChatBox).addChatNotes(_loc_14);
                    }
                }
            }
            if (this._currentChatBox != this._dicNameChatBox[ChatArea.Complex] && this._currentChatBox != this._dicNameChatBox[_loc_3] && !(this._currentChatBox == this._dicNameChatBox[ChatArea.World] && _loc_3 == ChatArea.Speaker))
            {
                return;
            }
            this._scrollPane.refreshPane();
            this._scrollPane.validateNow();
            this._scrollPane.update();
            _loc_9 = _loc_9 >= 0 ? (_loc_9) : (0);
            if (_loc_8)
            {
                this._scrollPane.verticalScrollPosition = this._scrollPane.maxVerticalScrollPosition;
            }
            else
            {
                this._scrollPane.verticalScrollPosition = _loc_9;
            }
            return;
        }// end function

        public function addTipNotes(param1:String, param2:String, param3:String = "complex", param4:int = 0, param5:Array = null, param6:int = 16777215) : void
        {
            var _loc_11:ChatItemData = null;
            var _loc_12:Vector.<ChatCellData> = null;
            var _loc_7:* = this._scrollPane.verticalScrollPosition == this._scrollPane.maxVerticalScrollPosition;
            var _loc_8:* = this._scrollPane.verticalScrollPosition;
            var _loc_9:Boolean = false;
            var _loc_10:Number = 0;
            _loc_9 = this._currentChatBox is ChatBox && (this._currentChatBox as ChatBox).isMaxLength();
            if (_loc_9)
            {
                _loc_10 = (this._currentChatBox as ChatBox).getChatNotesAtIndex(0).height;
                _loc_8 = _loc_8 - _loc_10;
            }
            _loc_11 = ObjectPool.getObject(ChatItemData);
            _loc_11.type = param1;
            _loc_12 = new Vector.<ChatCellData>;
            if (param4 == 0)
            {
                _loc_12 = _loc_12.concat(ChatMessageWorking.getCellDataByContent(param2, ChatStyle.getTitleColor(_loc_11.type)));
            }
            if (param4 == 1)
            {
                _loc_12 = _loc_12.concat(ChatMessageWorking.getCellDatasFilterHtml(param2, ChatStyle.getTitleColor(_loc_11.type), param5));
            }
            if (param4 == 2)
            {
                _loc_12 = _loc_12.concat(ChatMessageWorking.getCellDatasByAnalyzeRumor(param2, param5, param6));
            }
            if (!_loc_12 || _loc_12.length == 0)
            {
                return;
            }
            _loc_11.cellVector = _loc_12;
            var _loc_13:* = ObjectPool.getObject(ChatNotes);
            _loc_13.init(_loc_11, lineWidth, lineHeight);
            (this._dicNameChatBox[ChatArea.Complex] as ChatBox).addChatNotes(_loc_13);
            if (param3 != ChatArea.Complex)
            {
                _loc_11 = ObjectPool.getObject(ChatItemData);
                _loc_11.type = param1;
                _loc_12 = new Vector.<ChatCellData>;
                if (param4 == 0)
                {
                    _loc_12 = _loc_12.concat(ChatMessageWorking.getCellDataByContent(param2, ChatStyle.getTitleColor(_loc_11.type)));
                }
                if (param4 == 1)
                {
                    _loc_12 = _loc_12.concat(ChatMessageWorking.getCellDatasFilterHtml(param2, ChatStyle.getTitleColor(_loc_11.type)));
                }
                if (param4 == 2)
                {
                    _loc_12 = _loc_12.concat(ChatMessageWorking.getCellDatasByAnalyzeRumor(param2, param5, param6));
                }
                if (!_loc_12 || _loc_12.length == 0)
                {
                    return;
                }
                _loc_11.cellVector = _loc_12;
                _loc_13 = ObjectPool.getObject(ChatNotes);
                _loc_13.init(_loc_11, lineWidth, lineHeight);
                (this._dicNameChatBox[param3] as ChatBox).addChatNotes(_loc_13);
            }
            if (this._currentChatBox != this._dicNameChatBox[ChatArea.Complex] && this._currentChatBox != this._dicNameChatBox[param3])
            {
                return;
            }
            this._scrollPane.refreshPane();
            this._scrollPane.validateNow();
            this._scrollPane.update();
            _loc_8 = _loc_8 >= 0 ? (_loc_8) : (0);
            if (_loc_7)
            {
                this._scrollPane.verticalScrollPosition = this._scrollPane.maxVerticalScrollPosition;
            }
            else
            {
                this._scrollPane.verticalScrollPosition = _loc_8;
            }
            return;
        }// end function

        public function addRumorMsg(param1:String, param2:Array, param3:String = null) : void
        {
            var _loc_8:ChatItemData = null;
            var _loc_9:Vector.<ChatCellData> = null;
            if (!param3)
            {
                param3 = ChatType.Legent;
            }
            var _loc_4:* = this._scrollPane.verticalScrollPosition == this._scrollPane.maxVerticalScrollPosition;
            var _loc_5:* = this._scrollPane.verticalScrollPosition;
            var _loc_6:Boolean = false;
            var _loc_7:Number = 0;
            _loc_6 = this._currentChatBox is ChatBox && (this._currentChatBox as ChatBox).isMaxLength();
            if (_loc_6)
            {
                _loc_7 = (this._currentChatBox as ChatBox).getChatNotesAtIndex(0).height;
                _loc_5 = _loc_5 - _loc_7;
            }
            _loc_8 = ObjectPool.getObject(ChatItemData);
            _loc_8.type = param3;
            _loc_9 = new Vector.<ChatCellData>;
            var _loc_10:int = 16777215;
            var _loc_11:* = ColorConfig.instance.getChatColor("Rumor");
            if (_loc_11)
            {
                _loc_10 = _loc_11.intColor;
            }
            _loc_9 = _loc_9.concat(ChatMessageWorking.getCellDatasByAnalyzeRumor(param1, param2, _loc_10));
            if (!_loc_9 || _loc_9.length == 0)
            {
                return;
            }
            _loc_8.cellVector = _loc_9;
            var _loc_12:* = ObjectPool.getObject(ChatNotes);
            _loc_12.init(_loc_8, lineWidth, lineHeight);
            (this._dicNameChatBox[ChatArea.Complex] as ChatBox).addChatNotes(_loc_12);
            if (this._currentChatBox != this._dicNameChatBox[ChatArea.Complex])
            {
                return;
            }
            this._scrollPane.refreshPane();
            this._scrollPane.update();
            _loc_5 = _loc_5 >= 0 ? (_loc_5) : (0);
            if (_loc_4)
            {
                this._scrollPane.verticalScrollPosition = this._scrollPane.maxVerticalScrollPosition;
            }
            else
            {
                this._scrollPane.verticalScrollPosition = _loc_5;
            }
            return;
        }// end function

        public function addCopyMsg(param1:String, param2:Array, param3:Boolean = false) : Boolean
        {
            var _loc_8:ChatItemData = null;
            var _loc_9:Vector.<ChatCellData> = null;
            var _loc_10:ChatNotes = null;
            var _loc_11:int = 0;
            var _loc_12:ColorInfo = null;
            var _loc_4:* = this._scrollPane.verticalScrollPosition == this._scrollPane.maxVerticalScrollPosition;
            var _loc_5:* = this._scrollPane.verticalScrollPosition;
            var _loc_6:Boolean = false;
            var _loc_7:Number = 0;
            _loc_6 = this._currentChatBox is ChatBox && (this._currentChatBox as ChatBox).isMaxLength();
            if (_loc_6)
            {
                _loc_7 = (this._currentChatBox as ChatBox).getChatNotesAtIndex(0).height;
                _loc_5 = _loc_5 - _loc_7;
            }
            _loc_8 = ObjectPool.getObject(ChatItemData);
            _loc_8.type = ChatType.Copy;
            _loc_9 = new Vector.<ChatCellData>;
            _loc_11 = 16777215;
            _loc_12 = ColorConfig.instance.getChatColor("Rumor");
            if (_loc_12)
            {
                _loc_11 = _loc_12.intColor;
            }
            _loc_9 = _loc_9.concat(ChatMessageWorking.getCellDatasByAnalyzeRumor(param1, param2, _loc_11));
            if (!_loc_9 || _loc_9.length == 0)
            {
                return false;
            }
            _loc_8.cellVector = _loc_9;
            _loc_10 = ObjectPool.getObject(ChatNotes);
            _loc_10.init(_loc_8, lineWidth, lineHeight);
            var _loc_13:* = param3 ? (ChatArea.CrossGrop) : (ChatArea.Team);
            (this._dicNameChatBox[_loc_13] as ChatBox).addChatNotes(_loc_10);
            if (this._currentChatBox != this._dicNameChatBox[_loc_13])
            {
                return true;
            }
            this._scrollPane.refreshPane();
            this._scrollPane.update();
            _loc_5 = _loc_5 >= 0 ? (_loc_5) : (0);
            if (_loc_4)
            {
                this._scrollPane.verticalScrollPosition = this._scrollPane.maxVerticalScrollPosition;
            }
            else
            {
                this._scrollPane.verticalScrollPosition = _loc_5;
            }
            return true;
        }// end function

        public function changToChatItem(param1:String) : void
        {
            if (this._currentChatBox.name == param1)
            {
                return;
            }
            if (this._currentChatBox.parent)
            {
                this._currentChatBox.parent.removeChild(this._currentChatBox);
            }
            this._currentChatBox = this._dicNameChatBox[param1] as Sprite;
            this._scrollPane.source = this._currentChatBox;
            this._scrollPane.refreshPane();
            this._scrollPane.validateNow();
            this._scrollPane.update();
            this._scrollPane.verticalScrollPosition = this._scrollPane.maxVerticalScrollPosition;
            return;
        }// end function

        public function setSize(param1:Number, param2:Number) : void
        {
            this._scrollPane.setSize(param1, param2);
            this._scrollPane.source = this._currentChatBox;
            this._scrollPane.validateNow();
            this._scrollPane.verticalScrollPosition = this._scrollPane.maxVerticalScrollPosition;
            return;
        }// end function

        public function updateTabBarData() : void
        {
            return;
        }// end function

        public function set currentHeight(param1:Number) : void
        {
            this._currentHeight = param1;
            this.setSize(ChatModule.ChatWidth, this._currentHeight);
            this.y = -1 * (this._currentHeight + 43);
            return;
        }// end function

        public function get currentHeight() : Number
        {
            return this._currentHeight;
        }// end function

        public function set scrollAplha(param1:Number) : void
        {
            this._scrollPane.verticalScrollBar.alpha = param1;
            return;
        }// end function

        public function addSystemMsg(param1:String, param2:MsgTypeImpl) : void
        {
            var _loc_3:Boolean = false;
            var _loc_4:Number = NaN;
            var _loc_5:Number = NaN;
            var _loc_6:Boolean = false;
            if (this._currentChatBox == this.msgBox)
            {
                _loc_3 = this._scrollPane.verticalScrollPosition == this._scrollPane.maxVerticalScrollPosition;
                _loc_4 = this._scrollPane.verticalScrollPosition;
                _loc_5 = 0;
                _loc_6 = this.msgBox.isMaxLength();
                this.msgBox.addMsg(param1, param2);
                if (_loc_6)
                {
                    _loc_5 = this.msgBox.getMsgAtIndex(0).height;
                    _loc_4 = _loc_4 - _loc_5;
                }
                this._scrollPane.refreshPane();
                this._scrollPane.validateNow();
                this._scrollPane.update();
                _loc_4 = _loc_4 >= 0 ? (_loc_4) : (0);
                if (_loc_3)
                {
                    this._scrollPane.verticalScrollPosition = this._scrollPane.maxVerticalScrollPosition;
                }
                else
                {
                    this._scrollPane.verticalScrollPosition = _loc_4;
                }
            }
            else
            {
                this.msgBox.addMsg(param1, param2);
            }
            return;
        }// end function

        public function clearCurrentMsg() : void
        {
            if (this._currentChatBox is ChatBox)
            {
                (this._currentChatBox as ChatBox).reset();
            }
            else if (this._currentChatBox is ChatMsgBox)
            {
                (this._currentChatBox as ChatMsgBox).clear();
            }
            this._scrollPane.refreshPane();
            this._scrollPane.validateNow();
            this._scrollPane.update();
            this._scrollPane.verticalScrollPosition = this._scrollPane.maxVerticalScrollPosition;
            return;
        }// end function

        public function refresh() : void
        {
            this._scrollPane.refreshPane();
            this._scrollPane.validateNow();
            this._scrollPane.update();
            return;
        }// end function

    }
}
